package com.wzq.blog.base.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.Enumeration;

/**
 * 负责统一跳转页面的 controller
 */
@Controller
public class ViewController {

    @RequestMapping("/toView/{firstView}/{secondView}/{thirdView}")
    public String toView(
            @PathVariable("firstView") String firstView,
            @PathVariable("secondView") String secondView,
            @PathVariable("thirdView") String thirdView,
            HttpServletRequest request
    ){
        //获取前台所有参数的名字
        Enumeration<String> names = request.getParameterNames();
        while (names.hasMoreElements()){
            String name = names.nextElement();
            System.out.println("请求参数名==================》》》"+name);
            String value = request.getParameter(name);
            System.out.println("请求参数值=================》》》"+value);
            //设置到 request 域中
            request.setAttribute(name,value);
            String id = (String) request.getAttribute("id");
            System.out.println("ViewController---------------------------------id==========>>>" + id);
        }
        return firstView + File.separator + secondView + File.separator + thirdView;
    }
}
